package cn.billy._05_tran;

import org.apache.rocketmq.client.producer.*;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        // 创建生产者，创建组名
        TransactionMQProducer producer = new TransactionMQProducer("tran_hello_producer");
        // 连接NamesrvAddr
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动生成者
        producer.start();
        // 指定事务监听器
        producer.setTransactionListener(new MyTranIistener());
        // 创建消息题
        Message message = new Message("tran", "hello", "小贾是我幺儿".getBytes(StandardCharsets.UTF_8));
        // 发送消息

        TransactionSendResult send = producer.sendMessageInTransaction(message, null);
        System.out.println(send);
        producer.shutdown();

    }
}
